package com.zr.daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.zr.dao.CourseDao;
import com.zr.util.JDBCUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class CourseDaoImpl implements CourseDao {

	@Override
		public JSONArray getCnameByCid() {
			JSONArray js=new JSONArray();
			StringBuffer sql=new StringBuffer("");
			sql.append(" SELECT  course.cid,course.cname ");
			sql.append(" FROM course");
			Connection  con = JDBCUtil.getConnection();
			try {
				PreparedStatement  pst = con.prepareStatement(sql.toString());		
				ResultSet  rs = pst.executeQuery();
				while (rs.next()) {
					JSONObject j=new JSONObject();
					j.put("cid",rs.getInt("cid"));
					j.put("cname",rs.getString("cname"));
					js.add(j);
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
			return js;
		}

}
